{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'numpy.ndarray'>\n",
      "[0.         1.         1.41421356 1.73205081 2.         2.23606798\n",
      " 2.44948974 2.64575131 2.82842712 3.         3.16227766]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "a = np.arange(11)\n",
    "a\n",
    "print(type(a))\n",
    "# b = a.sqrt()\n",
    "print(np.sqrt(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1 2 3]\n",
      " [4 5 6]\n",
      " [7 8 9]]\n",
      "b  数组的维度： (3, 3)\n"
     ]
    }
   ],
   "source": [
    "b = np.array([np.arange(1, 4), np.arange(4, 7), np.arange(7, 10)])\n",
    "print(b)\n",
    "print(\"b  数组的维度：\", b.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3 1 0 0 4 4 0 0 1 1]\n",
      "int64\n"
     ]
    }
   ],
   "source": [
    "d = np.random.randint(5, size=10)\n",
    "print(d)\n",
    "print(d.dtype)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.34576877696432684\n",
      "[[-0.92723185 -1.35826497  0.75318469 -1.88046389]\n",
      " [ 0.98683709  0.92608949 -0.28941673 -0.28457641]]\n",
      "[[[-9.82940251e-01 -4.21152882e-01 -5.09333836e-01  1.37631320e+00]\n",
      "  [ 5.79342175e-01 -3.36819693e-01  9.86622829e-01 -1.12951694e+00]\n",
      "  [ 5.49301081e-01 -3.21693078e-04 -2.29812482e-01  1.09495011e+00]]\n",
      "\n",
      " [[-7.49330243e-01  9.84096208e-01  1.76597498e-01 -1.64354126e+00]\n",
      "  [-1.06199555e+00  7.81055384e-01 -5.19261616e-01  5.49938675e-01]\n",
      "  [-6.70322979e-01  3.53508976e-01  6.48081734e-01  4.79006997e-01]]]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "x = np.random.randn()\n",
    "print(x)\n",
    "y = np.random.randn(2, 4)\n",
    "print(y)\n",
    "z = np.random.randn(2, 3, 4)\n",
    "print(z)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1000,    2,    3,    4,    5,    6,    7,    8,    9,   10,   11,\n",
       "         12,   13,   14,   15,   16,   17,   18,   19,   20,   21,   22,\n",
       "         23,   24])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "a = np.arange(1,25)\n",
    "a\n",
    "a.size\n",
    "b = a.reshape(4,6)\n",
    "b\n",
    "b[(0,0)] = 1000\n",
    "b\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[array([1, 2]), array([3, 4]), array([5, 6]), array([7, 8])]\n",
      "[array([1, 2, 3]), array([4, 5]), array([6, 7, 8])]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "x = np.arange(1, 9)\n",
    "\n",
    "# 传递整数，平均分割\n",
    "a = np.split(x, 4)\n",
    "print(a)\n",
    "# 传递数组，按照位置进行分隔\n",
    "b = np.split(x, [3, 5])\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "axis=0 垂直方向 平均分隔\n",
      "[array([[1, 2, 3],\n",
      "       [4, 5, 6]]), array([[11, 12, 13],\n",
      "       [14, 15, 16]])]\n",
      "axis=1 水平方向 按位置分隔\n",
      "[array([[ 1,  2],\n",
      "       [ 4,  5],\n",
      "       [11, 12],\n",
      "       [14, 15]]), array([[ 3],\n",
      "       [ 6],\n",
      "       [13],\n",
      "       [16]])]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "# 创建两个数组\n",
    "a = np.array([[1, 2, 3], [4, 5, 6], [11, 12, 13], [14, 15, 16]])\n",
    "\n",
    "print(\"axis=0 垂直方向 平均分隔\")\n",
    "r = np.split(a, 2, axis=0)\n",
    "print(r)\n",
    "\n",
    "print(\"axis=1 水平方向 按位置分隔\")\n",
    "r = np.split(a, [2], axis=1)\n",
    "print(r)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "原数组：\n",
      "[  1.      4.55  123.      0.567  25.332]\n",
      "round舍入后：\n",
      "[  1.   5. 123.   1.  25.]\n",
      "[  1.    4.6 123.    0.6  25.3]\n",
      "[  0.   0. 120.   0.  30.]\n",
      "floor 向下取整：\n",
      "[  1.   4. 123.   0.  25.]\n",
      "None\n",
      "ceil 向上取整：\n",
      "[  1.   5. 123.   1.  26.]\n"
     ]
    }
   ],
   "source": [
    "a = np.array([1.0,4.55,123,0.567,25.332])\n",
    "print('原数组：')\n",
    "print(a)\n",
    "\n",
    "print('round舍入后：')\n",
    "print(np.around(a))\n",
    "\n",
    "print(np.around(a, decimals =1))\n",
    "print(np.around(a, decimals =-1))\n",
    "\n",
    "print('floor 向下取整：')\n",
    "print(print(np.floor(a)))\n",
    "\n",
    "print('ceil 向上取整：')\n",
    "print(np.ceil(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "原来的数组\n",
      "[[ 1  2  3  4  5]\n",
      " [ 6  7  8  9 10]\n",
      " [11 12 13 14 15]]\n",
      "调用 median 函数\n",
      "8.0\n",
      "调用 median 函数，axis=1 行的中值\n",
      "[ 3.  8. 13.]\n",
      "调用 median 函数，axis=0 列的中值\n",
      "[ 6.  7.  8.  9. 10.]\n"
     ]
    }
   ],
   "source": [
    "a = np.arange(1, 16).reshape(3, 5)\n",
    "print(\"原来的数组\")\n",
    "print(a)\n",
    "\n",
    "print(\"调用 median 函数\")\n",
    "print(np.median(a))\n",
    "\n",
    "print(\"调用 median 函数，axis=1 行的中值\")\n",
    "print(np.median(a, axis=1))\n",
    "\n",
    "print(\"调用 median 函数，axis=0 列的中值\")\n",
    "print(np.median(a, axis=0))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
